#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@author:chengyanan
@file: register_handle.py
@time: 2019/12/21  3:47 下午
"""
import os
import sys
path = os.path.dirname(os.getcwd())
sys.path.append(path)
from Page.register_page import RegisterPage
import time
from log.user_log import UserLog

class RegisterHandle:
    def __init__(self, driver):
        get_user_log = UserLog()
        self.loger = get_user_log.get_log()
        self.driver = driver
        self.register_p = RegisterPage(self.driver)

    # 点击首页登录按钮
    def click_index_loginbtn(self):
        time.sleep(3)
        self.register_p.click_loginbtn_element().click()

    # 点击账户按钮按钮
    def click_account_login_btn(self):
        self.register_p.click_account_login_element().click()

    # 输入用户名
    def send_user_name(self, name):
        self.loger.info("输入的用户名是："+name)
        self.register_p.get_name_element().send_keys(name)

    # 输入密码
    def send_user_password(self, password):
        self.loger.info("输入的用户名是："+password)
        self.register_p.get_password_element().send_keys(password)

    def get_user_text(self, info, user_info):
        try:
            if info == "name_null":
                text = self.register_p.get_name_error_element().text
            elif info == "password_null":
                text = self.register_p.get_password_error_element().text

            elif info == "name_and_password_null":
                text = self.register_p.get_name_password_null_element().text
        except:
            text = None
        return text

    # 点击登录按钮
    def click_register_button(self):
        self.register_p.get_login_btn().click()

    # 获取注册按钮文字
    def get_register_text(self):
        return self.register_p.click_account_login_element().text
